<template>
<div id="LeftNav">
  <div>
    <div class="tiao">
      <div class='logo'>
       <span class="jzd"> <i class="el-icon-ship"></i></span>
      </div>
      <el-radio-group v-model="isCollapse" style="" class="qiehuan">
        <div>
          <div @click="size1" style="display: inline-block">
            <el-radio-button :label="false"><i class="el-icon-s-fold bt"></i></el-radio-button>
          </div>
          <div @click="size2" style="display: inline-block">
            <el-radio-button :label="true"><i class="el-icon-s-unfold bt"></i></el-radio-button>
          </div>
        </div>
      </el-radio-group>
      <div class="ss">
        <div class="shuru"><el-input v-model="input" placeholder="请输入内容" size="small"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input></div>
      </div>
      <div class="youbian">
        <router-link to="shoppingCar"><div class="gwc"><span><i class="el-icon-s-goods"></i></span></div></router-link>
        <router-link to="personalInformation">
          <div class="denglu"><span><i class="el-icon-user-solid"></i></span></div>
        </router-link>
        <router-link to="user/login">
          <div class="gwc"><span><i class="el-icon-error" ></i></span></div>
        </router-link>
      </div>
    </div>
    <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
             :collapse="isCollapse "
             background-color="#323442"
             text-color="#fff"
             router
             active-text-color="#ffd04b">
        <el-menu-item index="home">
          <i class="el-icon-menu"></i>
          <span slot="title">首页</span>
        </el-menu-item>
      <template v-for="(item, index) in arr">
        <el-submenu v-if="item.permissionName !== '首页'" :index="index+''" :key="index">
          <template v-if="item.permission.length > 0">
            <template slot="title" class="t">
              <i class="el-icon-menu"></i>
              <span slot="title">{{item.permissionName}}</span>
            </template>
            <el-menu-item v-for="(a, b) in item.permission" :key="b" :index="menuName(a.permissionName)">{{a.permissionName}}</el-menu-item>
          </template>
          <template v-else>
            <template slot="title" class="t">
              <i class="el-icon-menu"></i>
              <span slot="title">{{item.permissionName}}</span>
            </template>
            <el-menu-item  :index="menuName(item.permissionName)">{{item.permissionName}}</el-menu-item>
          </template>
        </el-submenu>
      </template>

    </el-menu>
  </div>
  <div class="nr">
    <div class="view">
      <router-view/>
    </div>
  </div>
</div>
</template>
<script>
import config from '../config'
export default {
  data () {
    return {
      arr: [],
      isCollapse: true,
      input: '',
      logo2: 'logo2',
      nr2: 'nr2',
      qiehuan2: 'qiehuan2',
      ss2: 'ss2',
      denglu2: 'denglu2'
    }
  },
  name: 'leftNav',
  // components: {},
  created: function () {
    this.getMenu()
  },
  methods: {
    logout () {
      this.store.getters.loginEdit()
      this.$router.push({ path: '/user/login' })
    },
    menuName (item) {
      console.log('item')
      console.log(item)
      let temp
      if (config.componentList.get(item).split('/')) {
        temp = config.componentList.get(item).split('/')
      } else {
        temp = ['暂无此功能']
      }
      console.log(temp[temp.length - 1])
      return temp[temp.length - 1]
    },
    getMenu () {
      console.log('menu11')
      console.log(this.$store.getters.getMenuInfo)
      this.arr = this.$store.getters.getMenuInfo
    },
    handleOpen (key, keyPath) {
      window.console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      window.console.log(key, keyPath)
    },
    size1: function () {
      var dax = document.getElementsByClassName('logo')[0]
      dax.className = this.logo2
      var nr = document.getElementsByClassName('nr')[0]
      nr.className = this.nr2
      var qiehuan = document.getElementsByClassName('qiehuan')[0]
      qiehuan.className = this.qiehuan2
      var jzd = document.getElementsByClassName('jzd')[0]
      jzd.innerHTML = ''
      jzd.innerText = '经销系统 Pro'
      var denglu = document.getElementsByClassName('denglu')[0]
      denglu.className = this.denglu2
    },
    size2: function () {
      window.console.log('1')
      var dax = document.getElementsByClassName('logo2')[0]
      dax.className = 'logo'
      var nr = document.getElementsByClassName('nr2')[0]
      nr.className = 'nr'
      var qiehuan = document.getElementsByClassName('qiehuan2')[0]
      qiehuan.className = 'qiehuan'
      var jzd = document.getElementsByClassName('jzd')[0]
      jzd.innerText = ''
      jzd.innerHTML = '<i class="el-icon-ship"></i>'
      var denglu = document.getElementsByClassName('denglu2')[0]
      denglu.className = 'denglu'
    }
  }
}
</script>
<style scoped>
  .gwc{
    text-align: center;
    /*border: 1px solid black;*/
    display: inline-block;
    width: 50px;
    height: 50px;
    color: gray;
  }
  .gwc:hover{
    border-top: 2px solid black;
    color: rgb(247,132,0);
  }
  .denglu:hover{
    border-top: 2px solid black;
    color: rgb(247,132,0);
  }
  .denglu2:hover{
    border-top: 2px solid black;
    color: rgb(247,132,0);
  }
  .ssb:hover{
    /*border-top: 2px solid black;*/
    color: rgb(247,132,0);
  }
  .denglu{
    text-align: center;
    /*border: 1px solid black;*/
    display: inline-block;
    margin-left: 15px ;
    width: 50px;
    height: 50px;
    color: gray;
    transition: all 0.45s;
  }
  .denglu2{
    text-align: center;
    /*border: 1px solid black;*/
    display: inline-block;
    margin-left: 13px ;
    width: 50px;
    height: 50px;
    transition: all 0.45s;
  }
  .youbian{
    /*border: 1px solid red;*/
    position: fixed;
    right: 1%;
    top: 0;
    height: 50px ;
    line-height: 45px ;
    font-size: 25px ;
    color: white;
  }
  .shuru{
    line-height: 40px;
    display: inline-block;
    /*opacity: 0;*/
    margin-right: 20px;
  }
  .ssb{
    display: inline-block;
    width: 50px;
    height: 50px;
    /*border:1px solid red;*/
    text-align: center;
    line-height: 45px;
  }
  .ss{
    transition: all 0.45s;
    /*border: 1px solid red;*/
    position: fixed;
    right: 12%;
    top: 0;
    color: white;
    font-size: 23px;

  }
  .ss2{
    transition: all 0.45s;
    /*border: 1px solid red;*/
    height: 50px ;
    line-height: 45px ;
    position: fixed;
    left: 68.5%;
    top: 0;
    color: white;
    font-size: 23px;

  }
  .view {
    /*border: 1px solid red;*/
    width: 100%;
    /*margin: 0 auto;*/
  }
  .nr {
    transition: all 0.45s;
    /*border: 1px solid green;*/
    margin-left: 6.5%;
    width: 92%;
    margin-top: 70px;
  }

  .nr2 {
    transition: all 0.45s;
    /*border: 1px solid green;*/
    margin-left: 19%;
    width: 80%;
    margin-top: 80px;
    /*height: 1400px ;*/
  }

  .tiao {
    z-index: 999;
    width: 100%;
    position: fixed;
    top: 0px;
    height: 50px;
    /*overflow: hidden;*/
    background-color: rgb(229, 229, 229);
  }

  * {
    margin: 0;
    padding: 0;
    text-decoration: none;
  }

  .qiehuan {
    transition: all 0.45s;
    position: fixed;
    top: 6px;
    margin-left: 6%;
  }

  .qiehuan2 {
    transition: all 0.45s;
    position: fixed;
    top: 6px;
    margin-left: 18%;
  }

  .bt {
    /*font-size: 20px;*/
  }

  .logo {
    color: white;
    text-align: center;
    line-height: 50px ;
    /*width:236px;*/
    transition: all 0.43s;
    width: 64px;
    height: 50px;
    background-color: rgb(247, 132, 0);
    position: relative;
    left: 0;

  }

  .logo2 {
    color: white;
    line-height: 50px ;
    text-align: center;
    transition: all 0.43s;
    width: 17%;
    /*width: 64px;*/
    height: 50px;
    background-color: rgb(247, 132, 0);
    position: relative;
    left: 0;

  }

  #Nav {
    /*border: 1px solid black;*/
  }

  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 17%;
    min-height: 100%;
    height: 0px;
    overflow-x: hidden;
    overflow-y: scroll;
    position: fixed;
    top: 51px;
  }

  .el-menu-vertical-demo:not(.el-menu--collapse)::-webkit-scrollbar {
    display: none;
  }

  .el-menu {
    height: 0px;
    overflow-x: hidden;
    overflow-y: scroll;
    position: fixed;
    top: 51px;
    min-height: 800px;
  }

  .el-menu::-webkit-scrollbar {
    display: none;
  }

</style>
